import 'package:flutter/material.dart';
import 'package:flutter_syt/domain/login/register_email.dart';
import 'package:flutter_syt/domain/login/register_phone.dart';
import 'package:flutter_syt/domain/widgets/stupid_tabs.dart';
import 'package:flutter_syt/generated/l10n.dart';
import 'package:flutter_syt/utils/click_utils.dart';
import 'package:yyy_route_annotation/yyy_route_annotation.dart';

import 'widgets/login_container.dart';

@RoutePage(name: "register")
class Register extends StatefulWidget {
  const Register();

  @override
  _RegisterState createState() => _RegisterState();
}

class _RegisterState extends State<Register>
    with SingleTickerProviderStateMixin {
  TextEditingController mobileController = new TextEditingController();

  late TabController _tabController;

  // late PhoneWithAreaCodeEntity _phone;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(length: 2, vsync: this);
  }

  @override
  void dispose() {
    // phoneFocusNode.dispose();
    // codeFocusNode.dispose();
    // pwdFocusNode.dispose();

    // phoneEmailFocusNode.dispose();
    // codeEmailFocusNode.dispose();
    // pwdEmailFocusNode.dispose();

    _tabController.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // 避免键盘弹起时高度错误
      resizeToAvoidBottomInset: false,
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: ClickUtils.debounce(() {
          // 触摸收起键盘
          FocusScope.of(context).requestFocus(FocusNode());
        }),
        child: LoginContainer(
          // blurBackground: true,
          child: Column(
            children: [
              Container(
                padding:const EdgeInsets.symmetric(vertical: 0, horizontal: 15),
                height: 52,
                // color: Colors.red,
                child: NormalTabs(
                  // "register_email":"邮箱注册",
                  // "register_phone":"手机号注册",
                  [
                    ScrollerTabEntity.create(
                        'type', S.current.register_email, 0, ''),
                    ScrollerTabEntity.create(
                        'type', S.current.register_phone, 0, ''),
                  ],
                  _tabController,
                  textColor: Colors.black,
                  tabAlignment: TabAlignment.center,
                ),
              ),
              Container(
                // color: Colors.black.withOpacity(0.1),
                height: 12,
              ),
              // TabBarView(
              //   controller: _tabController,
              //   children: [_buildPhoneWidget(), _buildEmailWidget()],
              // ),
              SizedBox(
                height: 500,
                child: TabBarView(
                  controller: _tabController,
                  children: [
                    RegisterEmailPage(),
                    RegisterPhonePage(),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
